'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Interface IContactHistoryService
    Inherits IcqInterface.Interfaces.IContextService

    Sub Load()

    Sub Save()

    Sub AppendMessage(ByVal contact As ContactViewModel, ByVal message As MessageViewModel)

    Function GetHistory(ByVal contact As ContactViewModel) As List(Of MessageViewModel)

    Function GetHistory(ByVal contact As ContactViewModel, ByVal maxItems As Integer) As List(Of MessageViewModel)
End Interface

Public Class MessageViewModel
    Public Sub New(ByVal created As Date, ByVal recipient As ContactViewModel, ByVal foreground As Brush)
        _DateCreated = created
        _Recipient = recipient
        _Foreground = foreground
    End Sub

    Private ReadOnly _DateCreated As DateTime
    Public ReadOnly Property DateCreated() As DateTime
        Get
            Return _DateCreated
        End Get
    End Property

    Private ReadOnly _Recipient As ContactViewModel
    Public ReadOnly Property Recipient() As ContactViewModel
        Get
            Return _Recipient
        End Get
    End Property

    Private _Foreground As System.Windows.Media.Brush
    Public ReadOnly Property Foreground() As System.Windows.Media.Brush
        Get
            Return _Foreground
        End Get
    End Property
End Class

Public Class StatusChangedMessageViewModel
    Inherits MessageViewModel

    Private ReadOnly _Sender As ContactViewModel
    Private ReadOnly _Status As IcqInterface.Interfaces.IStatusCode

    Public Sub New(ByVal created As Date, ByVal sender As ContactViewModel, ByVal recipient As ContactViewModel, ByVal status As IcqInterface.Interfaces.IStatusCode, ByVal foreground As Brush)
        MyBase.New(created, recipient, foreground)

        _Sender = sender
        _Status = status
    End Sub

    Public ReadOnly Property Sender() As ContactViewModel
        Get
            Return _Sender
        End Get
    End Property

    Public ReadOnly Property Status() As IcqInterface.Interfaces.IStatusCode
        Get
            Return _Status
        End Get
    End Property
End Class

Public Class TextMessageViewModel
    Inherits MessageViewModel

    Public Sub New(ByVal message As IcqInterface.Interfaces.IMessage, ByVal foreground As Brush)
        Me.New(Date.Now, ContactViewModelCache.GetViewModel(message.Sender), ContactViewModelCache.GetViewModel(message.Recipient), message.Text, foreground)
    End Sub

    Public Sub New(ByVal created As Date, ByVal sender As ContactViewModel, ByVal recipient As ContactViewModel, ByVal message As String, ByVal foreground As Brush)
        MyBase.New(created, recipient, Foreground)

        _Sender = sender
        _Message = message
    End Sub

    Private ReadOnly _Sender As ContactViewModel
    Public ReadOnly Property Sender() As ContactViewModel
        Get
            Return _Sender
        End Get
    End Property

    Private ReadOnly _Message As String
    Public ReadOnly Property Message() As String
        Get
            Return _Message
        End Get
    End Property
End Class

Public Class OfflineTextMessageViewModel
    Inherits TextMessageViewModel

    Public Sub New(ByVal message As IcqInterface.IcqOfflineMessage, ByVal foreground As Brush)
        Me.New(Date.Now, ContactViewModelCache.GetViewModel(message.Recipient), ContactViewModelCache.GetViewModel(message.Sender), message.Text, message.OfflineSentDate, Foreground)
    End Sub

    Public Sub New(ByVal received As Date, ByVal sender As ContactViewModel, ByVal recipient As ContactViewModel, ByVal message As String, ByVal sent As Date, ByVal foreground As Brush)
        MyBase.New(received, sender, recipient, message, Foreground)

        _DateSent = sent
    End Sub

    Private ReadOnly _DateSent As DateTime
    Public ReadOnly Property DateSent() As DateTime
        Get
            Return _DateSent
        End Get
    End Property
End Class